package com.liming.common.config;

import com.liming.common.coder.decoder.FeignDecoder;
import com.liming.common.interceptors.FeignRequestInterceptor;
import feign.Logger;
import feign.RequestInterceptor;
import feign.Retryer;
import feign.codec.Decoder;
import feign.codec.Encoder;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;


/**
 * @author liming
 * @date 2025/1/9
 */
@Configuration
@RequiredArgsConstructor
public class FeignConfig {

    @Bean
    public Retryer feignRetryer() {
        return new Retryer.Default(300, TimeUnit.SECONDS.toMillis(1L),1);
    }

    @Bean
    public Encoder feignSpringDecoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new SpringEncoder(messageConverters);
    }

    @Bean
    public Decoder feignDecoder() {
        return new FeignDecoder();
    }

    @Bean
    public RequestInterceptor feignRequestInterceptor() {
        return new FeignRequestInterceptor();
    }

    @Bean
    public Logger.Level multipartLoggerLevel() {
        return Logger.Level.NONE;
    }
}
